package com.mstore.service;

import java.util.ArrayList;
import java.util.List;

import com.mstore.dao.BApplicationDao;
import com.mstore.pojo.BApplication;

public class BApplicationService {

	private BApplicationDao bApplicationDao;

	/**
	 * 提交申请
	 */
	public void saveApplication(BApplication bApplication) {
		bApplicationDao.save(bApplication);
	}

	public int findByAccountIdAndStatuPage(BApplication bApplication,
			String beginTime, String endTime) {
		return bApplicationDao.findByAccountIdAndStatuPage(bApplication,
				beginTime, endTime);
	}

	/**
	 * 根据条件查询所有记录
	 */
	public List<BApplication> findByAccountIdAndStatu(int index,
			BApplication bApplication, String beginTime, String endTime) {
		List<BApplication> bApplications = new ArrayList<BApplication>();
		List<Object> objects = bApplicationDao.findByAccountIdAndStatu(index,
				bApplication, beginTime, endTime);
		for (Object object : objects) {
			BApplication b = (BApplication) object;
			b.setCreateTime(b.getCreateTime().substring(0,
					b.getCreateTime().indexOf(".")));
			bApplications.add(b);
		}
		return bApplications;
	}

	/**
	 * id查询
	 */
	public BApplication auditorSelectById(BApplication bApplication) {
		BApplication b = (BApplication) bApplicationDao
				.auditorSelectById(bApplication);
		b.setCreateTime(b.getCreateTime().substring(0,
				b.getCreateTime().indexOf(".")));
		return b;

	}

	/**
	 * 根据shop查询
	 */
	public List<BApplication> getByShopId(int index, BApplication bApplication) {
		List<BApplication> bApplications = new ArrayList<BApplication>();
		List<Object> objects = bApplicationDao.getByShopId(index, bApplication);
		for (Object object : objects) {
			BApplication b = (BApplication) object;
			b.setCreateTime(b.getCreateTime().substring(0,
					b.getCreateTime().indexOf(".")));
			bApplications.add(b);
		}
		return bApplications;
	}

	public int getByShopPage(BApplication bApplication) {
		return bApplicationDao.getByShopPage(bApplication);
	}

	public List<BApplication> getByShopIdByTime(int index,
			BApplication bApplication, String beginTime, String endTime) {
		List<BApplication> bApplications = new ArrayList<BApplication>();
		List<Object> objects = bApplicationDao.getByShopIdByTime(index,
				bApplication, beginTime, endTime);
		for (Object object : objects) {
			BApplication b = (BApplication) object;
			b.setCreateTime(b.getCreateTime().substring(0,
					b.getCreateTime().indexOf(".")));
			bApplications.add(b);
		}
		return bApplications;
	}

	public int getByShopIdByTimePage(BApplication bApplication,
			String beginTime, String endTime) {
		return bApplicationDao.getByShopIdByTimePage(bApplication, beginTime,
				endTime);
	}

	/**
	 * 更新
	 */
	public void updateAuditorType(BApplication bApplication) {
		bApplicationDao.updateAuditorType(bApplication);
	}

	/**
	 * 通过id查找
	 */
	public BApplication getById(BApplication bApplication) {
		Object object = bApplicationDao.getById(bApplication);
		if (object == null) {
			return null;
		}
		return (BApplication) object;
	}

	public List<BApplication> getByAccountId(int index,
			BApplication bApplication) {
		List<BApplication> bApplications = new ArrayList<BApplication>();
		List<Object> objects = bApplicationDao.getByAccountId(index,
				bApplication);
		for (Object object : objects) {
			BApplication b = (BApplication) object;
			b.setCreateTime(b.getCreateTime().substring(0,
					b.getCreateTime().indexOf(".")));
			bApplications.add(b);
		}
		return bApplications;
	}

	public int getByAccountIdPage(BApplication bApplication) {
		return bApplicationDao.getByAccountIdPage(bApplication);
	}

	public BApplication selectByConsumeId(BApplication bApplication) {
		return (BApplication) bApplicationDao.selectByConsumeId(bApplication);
	}

	/**
	 * 通过balance_id查找
	 */
	public BApplication selectByBalaceId(BApplication bApplication) {
		return (BApplication) bApplicationDao.selectByBalaceId(bApplication);
	}
	/**
	 * 通过电话号码查找
	 * @param sessionFactory
	 */
	public List<BApplication> getByMobile(BApplication bApplication){
		List<BApplication> bApplications = new ArrayList<BApplication>();
		List<Object> objects = bApplicationDao.getByMobile(bApplication);
		for (Object object : objects) {
			BApplication b = (BApplication) object;
			b.setCreateTime(b.getCreateTime().substring(0,
					b.getCreateTime().indexOf(".")));
			bApplications.add(b);
		}
		return bApplications;
	}
	
	/**
	 * * 查询是否已申请
	 * * @param logBalanceId
	 */
	public int selectByBalaceIdCount(Long logBalanceId) {
		return bApplicationDao.selectByBalaceIdCount(logBalanceId);
	}
	
	public BApplicationDao getbApplicationDao() {
		return bApplicationDao;
	}

	public void setbApplicationDao(BApplicationDao bApplicationDao) {
		this.bApplicationDao = bApplicationDao;
	}

}
